<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<html>
<head> 
	<title>Videshop POS</title> 
	<link href="../css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
	<f:view>
		<table border="0" cellpadding="0" cellspacing="10">
			<tr>
				<td colspan="2"><h1>Videoshop POS</h1></td>
			</tr>
			<tr>
				<td valign="top">
					<table border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td>
								<!-- User section -->
								<f:subview id="userSection">
									<jsp:include page="user.jsp"/>
								</f:subview>
							</td>
						</tr>
						<tr>
							<td>
								<!-- Menu section -->
								<f:subview id="menuSection">
									<jsp:include page="menu.jsp"/>
								</f:subview>
							</td>
						</tr>
					</table>
				</td>
				<td valign="top" class="mainSection">
					<c:choose>
						<c:when test="${!empty userSection.staff}">
							<h2>Rental</h2>
							<c:choose>
								<c:when test="${empty rentalSection.customer}">
									<h:form>
										<h:panelGrid columns="3">
											<h:outputText styleClass="label" value="Customer Id"/>
											<h:inputText styleClass="text100" value="#{rentalSection.customerId}"/>
											<h:commandLink styleClass="button" action="#{rentalSection.start}">
												<f:verbatim escape="true">Start</f:verbatim>
											</h:commandLink>
										</h:panelGrid>
									</h:form>
								</c:when>
								<c:otherwise>
									<h:panelGrid columns="2">
										<h:outputText styleClass="label" value="Customer id"/>
										<h:outputText styleClass="field" value="#{rentalSection.customer.customerId}"/>
										<h:outputText styleClass="label" value="First Name"/>
										<h:outputText styleClass="field" value="#{rentalSection.customer.firstName}"/>
										<h:outputText styleClass="label" value="Last Name"/>
										<h:outputText styleClass="field" value="#{rentalSection.customer.lastName}"/>
									</h:panelGrid>
									
									<c:if test="${!empty rentalSection.rentals}">
										<h:form id="rentalForm">
											<h:dataTable 	id="rentalTable" 
															styleClass="dataTable"
															columnClasses="rentalTable2TitleCopyIdColumn,rentalTable2ImageColumn,rentalTable2TitleColumn,rentalTable2PriceColumn,rentalTable2ActionColumn"
															value="#{rentalSection.rentals}"
															var="rental"
											>
												<h:column headerClass="rentalTable2TitleCopyIdColumn">
													<f:facet name="header">
														<f:verbatim escape="true">Id</f:verbatim>
													</f:facet>
													<h:outputText value="#{rental.titleCopy.titleCopyId}"/>
												</h:column>
												<h:column headerClass="rentalTable2ImageColumn">
													<f:facet name="header">
													</f:facet>
													<h:graphicImage url="#{rental.titleCopy.medium.title.iconUrl}"/>
												</h:column>
												<h:column headerClass="rentalTable2TitleColumn" footerClass="rentalTable2TitleColumn">
													<f:facet name="header">
														<f:verbatim escape="true">Title</f:verbatim>
													</f:facet>
													<h:outputText value="#{rental.titleCopy.medium.title.titleName}"
													/>
													<f:facet name="footer">
														<f:verbatim escape="true">Total</f:verbatim>
													</f:facet>
												</h:column>
												<h:column headerClass="rentalTable2PriceColumn" footerClass="rentalTable2PriceColumn">
													<f:facet name="header">
														<f:verbatim escape="true">Price</f:verbatim>
													</f:facet>
													<h:outputText value="#{rental.firstCharge}">
														<f:convertNumber type="currency" minFractionDigits="2" maxFractionDigits="2"/>
													</h:outputText>
													<f:facet name="footer">
														<h:outputText value="#{rentalSection.totalPrice}">
															<f:convertNumber type="currency" minFractionDigits="2" maxFractionDigits="2"/>
														</h:outputText>
													</f:facet>
												</h:column>
												<h:column headerClass="rentalTable2ActionColumn">
													<f:facet name="header">
														<f:verbatim escape="true">Action</f:verbatim>
													</f:facet>
													<h:commandLink styleClass="button" action="#{rentalSection.delete}">
														<f:verbatim escape="true">Delete</f:verbatim>
													</h:commandLink>
												</h:column>
											</h:dataTable>
										</h:form>
									</c:if>
									
									<h:form>
										<h:panelGrid columns="3">
											<h:outputText styleClass="label" value="Enter Id"/>
											<h:inputText styleClass="text200" value="#{rentalSection.titleCopyId}"/>
											<h:commandLink styleClass="button" action="#{rentalSection.add}">
												<f:verbatim escape="true">Add</f:verbatim>
											</h:commandLink>
											<c:if test="${!empty rentalSection.rentals}">
												<h:commandLink styleClass="button" action="#{rentalSection.finish}"
												>
													<f:verbatim escape="true">Finish</f:verbatim>
												</h:commandLink>
												<h:commandLink styleClass="button" action="#{rentalSection.cancel}">
													<f:verbatim escape="true">Cancel</f:verbatim>
												</h:commandLink>
											</c:if>
										</h:panelGrid>
									</h:form>
								</c:otherwise>
							</c:choose>
						</c:when>
						<c:otherwise>
							Please login 
						</c:otherwise>
					</c:choose>
				</td>
			</tr>
		</table>
	</f:view>
</html>